import json

indexList = []

ques=[]
n=0
while not n:
    print("请输入文件编号")
    a=input()
    name="./ques"+a+".json"
    try:
        with open(file = name, mode = 'r', encoding = 'utf8') as f:
            ftext = f.read()
        n=1
    except:
        continue

data = json.loads(ftext)
ques=data["map"]

def firstEnpty():
    for i in range(0,9):
        for j in range(0,9):
            if ques[i][j] == 0:
                indexList.append([i,j])
                return

def LastEnpty():
    for i in range(8,-1,-1):
        for j in range(8,-1,-1):
            if ques[i][j] == 0:
                return [i,j]

def isEmpty():
    now,last = indexList[-1]
    last += 1
    for i in range(now,9):
        if i != now:
            last = 0
        for j in range(last,9):
            if ques[i][j] == 0:
                indexList.append([i,j])
                return
  
def Check(x,y):
    temp = ques[x][y]
    for i in range(9):
        if ques[x][i] == temp and i != y:
            return False
    for i in range(9): 
        if ques[i][y] == temp and i != x:
            return False
    xx = int(x / 3)
    yy = int(y / 3)
    for i in range(3):
        for j in range(3):
            if ques[xx * 3 + i][yy * 3 + j] == temp and (xx * 3 + i) != x and (yy * 3 + j) != y:
                return False
    return True

def main():
    firstEnpty()
    last = LastEnpty()
    m,n = last
    while Check(m,n) != True or ques[m][n] == 0:
        x,y = indexList[-1]
        if Check(indexList[-1][0],indexList[-1][1]) == True and ques[x][y] <= 9 and 0 < ques[x][y]:
            isEmpty()
        else:
            if ques[x][y] >= 9:
                ques[indexList[-1][0]][indexList[-1][1]] = 0
                indexList.pop()
            ques[indexList[-1][0]][indexList[-1][1]] += 1
    for i in range(9):
        print(ques[i])

if __name__ == "__main__":
    main()